﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace GenerateAdminPage.Classes.FrmClasses
{
    #region USING
    using GenerateAdminPage.Classes.Base;
    using GenerateAdminPage.Classes.Helpers;
    using GenerateAdminPage.Classes.DBStructure;
    #endregion

    public abstract class AbstractFrmClass: AbstractBase
    {
        /// <summary>
        /// Method is responsible for select generate type such as: view, frmclass or repository
        /// </summary>
        /// <returns>Correspding generate class</returns>
        public static AbstractBase SelectGenerateType(Table tbl, Table tblMany, GenerateType type)
        {
            switch (type)
            {
                case GenerateType.SINGLE:
                    return new FrmClassesSingle();

                case GenerateType.COMPLEX:
                    return new FrmClassesComplex();

                case GenerateType.ONE_TO_MANY:
                    return new FrmClassOneToMany();

                case GenerateType.SELECT_MANY_FOR_ONE:
                    return new FrmClassesSelectManyForOne();
            }
            return null;
        }

        public override string GenerateUsingRegion()
        {
            StringBuilder Result = new StringBuilder();

            Result.AppendLine(TAB + "#region using");
            Result.AppendLine(TAB + "using DevComponents.DotNetBar;");
            Result.AppendLine(TAB + "using " + GlobalVariables.g_sNameSpace + ".Models;");
            Result.AppendLine(TAB + "using " + GlobalVariables.g_sNameSpace + ".Repositories;");
            Result.AppendLine(TAB + "using " + GlobalVariables.g_sNameSpace + ".Helpers;");
            if (TblOne.Attributes.FirstOrDefault( n => (GlobalVariables.g_sTableNguoiDung.Contains(n.ReferTo))) != null)
            {
                Result.AppendLine(TAB + "using " + GlobalVariables.g_sNameSpace + ".UsersManager;");
            }
            Result.AppendLine(TAB + "using System.Data;");
            Result.AppendLine(TAB + "using System.Drawing;");
            Result.AppendLine(TAB + "using System.IO;");
            Result.AppendLine(TAB + "#endregion");

            return Result.ToString();
        }

        public override string GenerateClass()
        {
            return string.Empty;
        }
    }
}
